<template>
  <div class="jeecg-basic-table jeecg-basic-table-form-container">
    <!--查询区域-->
    <div class="">
      <a-form
        ref="formRef"
        class="jeecg-basic-table-form"
        @keyup.enter.native="reload"
        :model="queryParam"
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
      >
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item label="委托单位" name="entName">
              <!-- <j-dict-select-tag placeholder="" v-model:value="queryParam.entName" :show-choose-option="false"
                dictCode="lab_enterprise,ent_name,ent_name" /> -->
              <j-input placeholder="" v-model:value="queryParam.entName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item label="送样人" name="handler">
              <j-input placeholder="" v-model:value="queryParam.handler"></j-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item label="样品大类" name="sampleType">
              <j-dict-select-tag
                placeholder=""
                v-model:value="queryParam.sampleType"
                :show-choose-option="false"
                dictCode="lab_items,name,id,type='A'"
              />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item label="经办时间" name="handler">
              <a-date-picker valueFormat="YYYY-MM-DD" v-model:value="queryParam.handlDate"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <!-- <a-col :lg="6">
              <a-form-item label="样品类别" name="sampleSort">
                <j-dict-select-tag placeholder="" v-model:value="queryParam.sampleSort" :show-choose-option="false"
                  dictCode="yn" />
              </a-form-item>
            </a-col> -->
            <!-- <a-col :lg="6">
              <a-form-item label="样品处置" name="sampleDispose">
                <j-dict-select-tag placeholder="" v-model:value="queryParam.sampleDispose" :show-choose-option="false"
                  dictCode="sample_dispose" />
              </a-form-item>
            </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="reload">查询</a-button>
                <a-button preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
                <a @click="toggleSearchStatus = !toggleSearchStatus" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <Icon :icon="toggleSearchStatus ? 'ant-design:up-outlined' : 'ant-design:down-outlined'" />
                </a>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
      <!--字段回显插槽-->
      <template #htmlSlot="{ text }">
        <div v-html="text"></div>
      </template>
      <template #fileSlot="{ text }">
        <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
        <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <TableModal @register="registerSamModal" @success="handleSuccess"></TableModal>
  </div>
</template>

<script lang="ts" name="entrust-labEntrust" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useModal } from '/@/components/Modal';
  import { columnsA } from './LabEntrust.data';
  import { auditList, getImportUrl, getExportUrl } from './LabEntrust.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  // import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import TableModal from './components/LabEntrustFormA.vue';
  import { JInput, JDictSelectTag } from '/@/components/Form';
  // import { defHttp } from '/@/utils/http/axios';

  const formRef = ref();
  const queryParam = reactive<any>({
    auditMark: '初审中',
  });
  //注册model
  const [registerSamModal, { openModal }] = useModal();

  //注册table数据
  const { tableContext } = useListPage({
    tableProps: {
      title: '委托初审',
      api: auditList,
      columns: columnsA,
      canResize: false,
      useSearchForm: false,
      showIndexColumn: true,
      showTableSetting: false,
      actionColumn: {
        width: 100,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam);
      },
    },
    exportConfig: {
      name: '委托信息表',
      url: getExportUrl,
      params: queryParam,
    },
    importConfig: {
      url: getImportUrl,
      success: handleSuccess,
    },
  });

  const [registerTable, { reload }, { selectedRowKeys }] = tableContext;

  /**
   *  初审事件（用的时编辑事件）只是详情中显示的按钮不同。
   */
  function handleEdit(record: Recordable) {
    openModal(true, {
      record,
      isUpdate: true,
      disabled: false,
      showFooter: true,
    });
    //获取服务token和员工票据,员工id
    // defHttp.get({url:servestoken},{ isTransformResponse: false }).then((srcs) => {
    //   //员工id
    //   let yaunid = srcs.cardid;
    //   //服务token
    //   let tokenServe = srcs.tokenServe;
    //   //员工票据
    //   let employeeTicket = srcs.employeeTicket;
    //   //封装请求
    //   let datae = {
    //     businessCreateUserId:yaunid,
    //     businessCreateUserPositionId:'',
    //     content:'flowlame=12',
    //     description:'',
    //     name:'12',
    //   }
    //   //调用签证
    //   //获取签名
    //   window.SCZZ_SIGN.open({
    //         token: employeeTicket, //员工票据，通过获取员工票据接口获取得到
    //         data: datae, //签证数据,用于签证校验，其内容见下文
    //         type: 'PERSONAL_SIGNATURE', //类型（个人签名:PERSONAL_SIGNATURE，单位签章:CORP_SIGNATURE），根据不同的类型打开对应的签证页面
    //         mobile: false, //移动端调用时需要传递
    //         call: function(res) {
    //           if(res.data.imageUrl){
    //             console.log("ddddddd");
    //             console.log(res.data.imageUrl);
    //             // 把签名存在数据库
    //             let urls = signature+'?id='+yaunid+'&paramasa='+res.data.imageUrl
    //             defHttp.post({url:urls})
    //           }
    //             //回调，接收一个结果对象，该对象里包含sdk的响应状态码code，响应信息msg，当响应code为1000时有响应数据data，响应数据内容见下文
    //         }
    //     })

    // })
  }

  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }

  /**
   * 初审事件（用的时编辑事件）只是详情中显示的按钮不同。
   */
  function getTableAction(record) {
    return [
      {
        label: '初审',
        onClick: handleEdit.bind(null, record),
      },
    ];
  }

  /* ----------------------以下为原生查询需要添加的-------------------------- */
  const toggleSearchStatus = ref<boolean>(false);
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });
  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }
</script>
<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }

    .query-group-cust {
      width: calc(50% - 15px);
      min-width: 100px !important;
    }

    .query-group-split-cust {
      width: 30px;
      display: inline-block;
      text-align: center;
    }
  }

  // .jeecg-basic-table-form {
  //   height: 58px;
  // }

  :deep(.ant-table-title) {
    display: none;
  }
</style>
